import random
from datetime import datetime


money=1000.00
goods=["泡面","香肠","绿茶","红茶","帽子","背包","雨伞","空调","水壶","雨衣"]
price=[5,3,3,3,20,50,20,1000,30,50]
shopping_car=[]
shopping_count=[]
shopping_time=[]
a=[]
i=0
sum=0

print("正在为您抽取优惠卷:")
for n1 in range(1,11):
    print(f"{n1}:  {goods[n1-1]}5折卷")
print()
r=random.randint(0,9)
price[r]*=0.5
print(f"恭喜您抽中{goods[r]}5折卷")
print()
while True:
    print("请输入您的操作：")
    print("购物：请输入1")
    print("充值：请输入2")
    print("购物车：输入3")
    print("退货：请输入4")
    print("退出：请输入Q")
    print()
    x=input()

    if x=="1":
        print("以下为货物信息：")
        for n in range(1, 11):
            print(f"{n}:  {goods[n-1]},价格为：{price[n-1]}")
        name=input("请输入您要购买的商品名字：  ")
        try:
            a.append(goods.index(name))
            count=int(input("请输入要购买的数量"))
            shopping_count.append(count)
            if money>=price[a[i]]:
                sum+=price[a[i]] * shopping_count[i]
                money-=price[a[i]] * shopping_count[i]
                shopping_car.append(name)
                time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                shopping_time.append(time)
                i+=1
                print(f"恭喜，购买成功！您的卡余额还剩{money}")
            else:
                print("穷鬼，钱不够！到其他超市购买！")
        except ValueError:
            print("没有这个商品，别瞎弄！")
            continue

    elif x=="2":
        c=int(input("请输入充值的金额："))
        money+=c
        print(f"充值成功!您的余额为{money}")

    elif x == "3":
        print("购物车：")
        for n in range(0,i):
            print(f"{shopping_car[n]}  x {shopping_count[n]}  总价：{price[a[n]]*shopping_count[n]}元")
        print()

    elif x == "4":
        name=input("请输入要退货的商品：")
        try:
            xb=shopping_car.index(name)
            sum -= price[a[xb]] * shopping_count[xb]
            money += price[a[xb]] * shopping_count[xb]
            shopping_car.pop(xb)
            shopping_count.pop(xb)
            shopping_time.pop(xb)
            i-=1
            print("已退回商品")
        except ValueError:
            print("购物车中没有该商品")
            continue

    elif x=="Q":
        print("购物小票：")
        for n in range(0,i):
            print(f"{shopping_time[n]}  {shopping_car[n]} x {shopping_count[n]}  总价：{price[a[n]]*shopping_count[n]}元")
        print(f"您一共花费{sum}元，您的余额为{money}")
        break
    else:
        print("您的输入有误!")
        continue


